package jeecg.httpsock;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

public class HttpResponse {

	private static final int BUFFER_SIZE = 1024;  
	private OutputStream output =null;
	public HttpResponse(OutputStream output){
		this.output = output;
	}
	
	
	public  void sendMsg(File file){
		byte buffer[] = new byte[BUFFER_SIZE];
		FileInputStream fis = null;
		try {
			 if(file.exists()){
				 fis = new 	FileInputStream(file);
				 int ch = fis.read(buffer);  
	             while(ch != -1) {  
	                    output.write(buffer, 0, ch);  
	                    ch = fis.read(buffer, 0, BUFFER_SIZE);  
	             }  
			 }else{
				 String errMsg = "file not found";
				 output.write(errMsg.getBytes());
			 }
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(fis!=null){
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	
}
